// components/star/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    flag: {
      type: Boolean
    },
    count: {
      type: Number
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    yesSrc: 'images/star.png',
    noSrc: 'images/nostar.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tapStar: function (event) {
      let flag = this.properties.flag
      let count = this.properties.count

      count = flag ? count-1 : count+1

      this.setData({
        count: count,
        flag: !flag
      })

      let behavior = this.properties.flag ? 'likes':'dislikes'
      this.triggerEvent('like',{
        behavior: behavior
      },{})
    }
  }
})
